package gtkwire.widget.cairo;

/**
* CairoPattern is the paint with which cairo draws. Corresponding struct in Cairo API documentation is called cairo_pattern_t.
* A pattern is the source for cairo drawing operations, although they can also be used as masks, that is, as the brush too.
* <p>
*  There are different subtypes of CairoPattern for different types of sources; 
* solid opaque color, semitransparet color, linear gradient and radial gradient
*/
public abstract class CairoPattern
{

	/**
	* Pixels outside of the source pattern are fully transparent. 
	* Field value is used to describe how pattern color/alpha will be determined for areas "outside" the pattern's natural area.
	*/
	public static final int CAIRO_EXTEND_NONE = 0;
	/**
	* Pixels outside of the source pattern are fully transparent. 
	* Field value is used to describe how pattern color/alpha will be determined for areas "outside" the pattern's natural area.
	*/
	public static final int CAIRO_EXTEND_REPEAT = 1;
	/**
	* The pattern is tiled by reflecting at the edges.
	* Field value is used to describe how pattern color/alpha will be determined for areas "outside" the pattern's natural area.
	*/
	public static final int CAIRO_EXTEND_REFLECT = 2;
	/**
	* Pixels outside of the pattern copy the closest pixel from the source.
	* Field value is used to describe how pattern color/alpha will be determined for areas "outside" the pattern's natural area.
	*/
	public static final int CAIRO_EXTEND_PAD = 3;

	/**
	* A high-performance filter, with quality similar to CAIRO_FILTER_NEAREST.
	*/
	public static final int CAIRO_FILTER_FAST = 0;
	/**
	* A reasonable-performance filter, with quality similar to CAIRO_FILTER_BILINEAR.
	*/
	public static final int CAIRO_FILTER_GOOD = 1;
	/**
	* The highest-quality available, performance may not be suitable for interactive use.
	*/
	public static final int CAIRO_FILTER_BEST = 2;
	/**
	* Nearest-neighbor filtering.
	*/
	public static final int CAIRO_FILTER_NEAREST = 3;
	/**
	* Linear interpolation in two dimensions.
	*/
	public static final int CAIRO_FILTER_BILINEAR = 4;
	/**
	* This filter value is currently unimplemented, and should not be used in current code.
	*/
	public static final int CAIRO_FILTER_GAUSSIAN = 5;

	protected int pattern_id;
	
	private static int next_pattern_id = 0;

	private CairoMatrix matrix;

	protected CairoPattern()
	{
		pattern_id = next_pattern_id;
		next_pattern_id++;//will overflow, but practically never.
	}

	//-------------------------------------------------------------- INTERFACE
	/**
	* Returns pattern id.
	*/
	protected int get_id(){ return pattern_id; }
	/**
	* Use field value like CAIRO_EXTEND_REFLECT to describe how pattern color/alpha will be determined for areas "outside" the pattern's natural area.
	*/
	public void set_extend( int extendType ){ p_set_extend( pattern_id, extendType ); }

	
	/**
	* Sets the filter to be used for resizing when using this pattern.
	*/
	public void set_filter( int filterType ){ p_set_filter( pattern_id, filterType); }
	
	//------------------------------------------------------------- NATIVE INTERFACE
	/**
	* Native interface.
	*/
	protected native void p_create_pattern_radial( 	int pid,
							double cx0,
                                                        double cy0,
                                                        double radius0,
                                                        double cx1,
                                                        double cy1,
                                                        double radius1);
	/**
	* Native interface.
	*/
	protected native void p_create_pattern_linear( 	int pid,
							double x0,
							double y0,
							double x1,
							double y1);
	/**
	* Native interface.
	*/
	protected native void p_create_pattern_rgb (	int pid,
							double red,
							double green,
							double blue);
	/**
	* Native interface.
	*/
	protected native void p_create_pattern_create_rgba(
							int pid,
							double red,
							double green,
							double blue,
							double alpha);
	/**
	* Native interface.
	*/
	protected native void p_destroy_pattern( int pid );
	/**
	* Native interface.
	*/
	protected native void p_add_color_stop_rgb( int pid, double offset, double red, double green, double blue );
	/**
	* Native interface.
	*/
	protected native void p_add_color_stop_rgba( int pid, double offset, double red, double green, double blue, double alpha );
	/**
	* Native interface.
	*/
	private native int p_cairo_pattern_status ( int pid);
	/**
	* Native interface.
	*/
	protected native void p_set_extend( int pid, int ext_type );
	/**
	* Native interface.
	*/
	protected native void p_set_filter( int pid, int filter);
	//protected native void p_set_matrix(...)

	//-------------------------------------------- RELEASE NATIVE SIDE RESOURCES
	/**
	* Destroys native object.
	*/
	public void finalize() throws Throwable
	{
		p_destroy_pattern( pattern_id );
	}
}